import 'package:flutter/material.dart';
import 'package:flutter02/res/list_data.dart';

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  List<Widget> _initListData() {
    return listData
        .map((value) => Container(
              alignment: Alignment.center,
              decoration:
                  BoxDecoration(border: Border.all(color: Colors.black26)),
              child: Column(
                children: [
                  SizedBox(
                    height: 140,
                    child: Image.network(
                      value["imageUrl"],
                      fit: BoxFit.cover,
                    ),
                  ),
                  SizedBox(
                    height: 30,
                    child: Text(
                      value['title'],
                      style: const TextStyle(color: Colors.blue, fontSize: 18),
                    ),
                  ),
                ],
              ),
            ))
        .toList();
  }

  @override
  Widget build(BuildContext context) {
    return GridView.count(
      padding: const EdgeInsets.all(10),
      crossAxisSpacing: 10,
      mainAxisSpacing: 10,
      childAspectRatio: 0.9,
      crossAxisCount: 2,
      // maxCrossAxisExtent: 180,
      children: _initListData(),
    );
  }
}
